package atack.tesis.kelluntekun;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.*;

public class KelluntekunApplication extends Application implements HttpServletRequestListener{
	private static final long serialVersionUID = 1L;
	public static final String PERSISTENCE_UNIT = "kelluntekunbd"; 
	private static ThreadLocal<KelluntekunApplication> instance = new ThreadLocal<KelluntekunApplication>();
	

	@Override
	public void init() {
		setInstance(this); // So that we immediately have access to the current application 	
//		setTheme("kellun");
		Window mainWindow = new Window("Kelluntekun 0.1");
		mainWindow.setSizeFull();

		
//		mainUserHandlerView mainView = new mainUserHandlerView();
		/*las ventanas en vaadin vienen por defecto con un verticalLayout dentro.
		 * es mejor hacer un setContent para reemplazar.*/
//		mainWindow.setContent(mainView);
		mainWindow.setContent(new LoginScreen());
		
		setMainWindow(mainWindow);
	}
	
	/**
	 * @return la instancia de la Aplicación actual.
	 */
	public static KelluntekunApplication getInstance(){
		return instance.get();
	} 	 


	/**
	 * Setea la instancia de la aplicación actual.
	 * @param kApplication
	 */
	public static void setInstance(KelluntekunApplication kApplication){
		// TODO Auto-generated method stub
		instance.set(kApplication);
	}

	@Override
	public void onRequestStart(HttpServletRequest request,HttpServletResponse response){
		instance.set(this);		
	}

	@Override
	public void onRequestEnd(HttpServletRequest request,HttpServletResponse response){
		instance.remove();
	}
}
